package database

import (
	"GOPAAS/configs/config"
	"fmt"
	"github.com/sirupsen/logrus"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func connectMysql(config *config.DatabaseConfig) *gorm.DB {
	dsn := "%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local"
	dsn = fmt.Sprintf(dsn, config.User, config.Password, config.Host, config.Port, config.DbName)
	mysqlDb, err := gorm.Open(mysql.Open(dsn), DConfig)
	if err != nil {
		logrus.Error(err)
		panic("failed to connect database")
	}
	return mysqlDb
}
